/**
 * Created by CK on 2016/6/30.
 */
$(document).ready(function() {
    var schoolId = xhTool.getQuery('iSchoolId');
    var list = $('#List');
    $('#xh_form').attr('action', 'modifyGroupData?iSchoolId=' + schoolId);
    $('.xh-datagrid-toolbar').parseToolbar();
    $('.xh-form').parseForm($('#bt_form_add, #bt_form_edit'));
    list.initDataGrid(baseUrl + 'School/getGroupDgData', {"queryParams": {"iSchoolId": schoolId}})
        .setSelectThenEnable(
            ['bt_list_del', 'bt_list_enable', 'bt_list_disable'],
            ['bt_list_addStudent', 'bt_list_addTeacher', 'bt_list_SetAppStore']
        );
    /** 列表 **/
    $('#bt_list_add').click(function(){
        $.overtFun.clickAddList(list);
    });
    $('#bt_list_del').click(function () {
        var ids = list.getDataGridSelectedFields('iSAGId');
        $.overtFun.clickDelList(ids, baseUrl + 'School/delSchoolGroupData?iSchoolId=' + schoolId);
    });
    $('#bt_list_enable').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var ids = list.getDataGridSelectedFields('iSAGId');
        $.overtFun.setModelState('setSchoolGroupState?iSchoolId=' + schoolId, ids, 'enable');
    });
    $('#bt_list_disable').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var ids = list.getDataGridSelectedFields('iSAGId');
        $.overtFun.setModelState('setSchoolGroupState?iSchoolId=' + schoolId, ids, 'disable');
    });
    //如果有修改权限,双击行后执行OpenEditAppDiv方法
    if($('#bt_form_edit').length > 0){
        DataGrid.onDblClickRow = function(rowIndex, rowData){
            openEditPage(rowData.iSAGId, 'XHSchool_AppGroup');
        }
    }
    //添加学生按钮
    $('#bt_list_addStudent').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var groupId = list.getDataGridSelectedField('iSAGId');
        var src = baseUrl + 'School/schoolOutGroupStudentList?iSAGId=' + groupId + '&iSchoolId=' + schoolId;
        window.top.xhTop.showModal({
            title: '增加学生',
            content: "<iframe frameborder='0' style='width: 100%;height:500px;' src='" + src + "'></iframe>",
            button: '确认增加',
            size: 'lg'
        });
    });
    //添加教师按钮
    $('#bt_list_addTeacher').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var groupId = list.getDataGridSelectedField('iSAGId');
        var src = baseUrl + 'School/schoolOutGroupTeacherList?iSAGId=' + groupId + '&iSchoolId=' + schoolId;
        window.top.xhTop.showModal({
            title: '增加教师',
            content: "<iframe frameborder='0' style='width: 100%;height:500px;' src='" + src + "'></iframe>",
            button: '确认增加',
            size: 'lg'
        });
    });
    //设置应用按钮
    $('#bt_list_SetAppStore').click(function(){
        if($(this).checkButtonDisabled()) return false;
        var groupId = list.getDataGridSelectedField('iSAGId');
        var src = baseUrl + 'School/schoolGroupAppList?iSAGId=' + groupId + '&iSchoolId=' + schoolId;
        window.top.xhTop.showModal({
            title: '应用组应用设置',
            content: "<iframe frameborder='0' style='width: 100%;height:500px;' src='" + src + "'></iframe>",
            size: 'lg'
        });
    });
    /** 表单 **/
    $('#bt_form_add, #bt_form_edit').click(function () {
        $.overtFun.clickSubmitForm();
    });
    $('#bt_form_back').click(function () {
        $.overtFun.clickBackForm();
    });
    $('#bt_form_reset').click(function () {
        $.overtFun.clickResetForm();
        $('#XHSchool_AppGroup_iSchoolId').val(schoolId);
    });
});
////删除
//function del(){
//    var ids = getDataGridSelectedFields("List","iSAGId");//获取List中选中的ID字段值
//    $.post("delSchoolGroupData",{ids:ids,target:"XHSchool_AppGroup"},function(result){
//        alertMessage("结果",result);//弹窗提示
//        dataGridReload("List");//刷新表单
//    });
//}
////打开修改窗体
//function OpenEditDiv(_id){
//    $(".xh-datagrid").parent().hide();
//    $.post(baseUrl+"Other/createFormWithData",{id:_id,target:"XHSchool_AppGroup"},function(form){
//        $(".xh-area-form").html(form);
//        parseForm('.xh-form');
//        $(".xh-area-form table").find("[must=true]").each(function(){
//            $(this).parent().removeClass("has-warning").addClass("has-success");
//        });
//        $(".xh-form").fadeIn();
//        $("#bt_form_add,#bt_form_reset").hide();
//        $("#bt_form_edit").show();
//        setButtonEnable("bt_form_edit","bs");
//        bindFormMust('.xh-form');
//    });
//}
//function setSchoolGroupState(target){
//    var ids = list.getDataGridSelectedFields('iSAGId');
//    $.post("setSchoolGroupState",{sSAGId:ids,target:target},function(result){
//        if(result == 1) dataGridReload("List");//刷新
//        else $('body').append(result);
//    });
//}